
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>模块(Module) · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="mix.html" />
    
    
    <link rel="prev" href="pipe-operator.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">第一部分：基础</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="basics.html">
            
                <a href="basics.html">
            
                    
                    基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="collections.html">
            
                <a href="collections.html">
            
                    
                    集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="enum.html">
            
                <a href="enum.html">
            
                    
                    Enum 模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="pattern-matching.html">
            
                <a href="pattern-matching.html">
            
                    
                    模式匹配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="control-structures.html">
            
                <a href="control-structures.html">
            
                    
                    控制语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="functions.html">
            
                <a href="functions.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="pipe-operator.html">
            
                <a href="pipe-operator.html">
            
                    
                    管道操作符
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.9" data-path="modules.html">
            
                <a href="modules.html">
            
                    
                    模块(Module)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="mix.html">
            
                <a href="mix.html">
            
                    
                    Mix
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="sigils.html">
            
                <a href="sigils.html">
            
                    
                    魔符(Sigil)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="documentation.html">
            
                <a href="documentation.html">
            
                    
                    文档模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="testing.html">
            
                <a href="testing.html">
            
                    
                    测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="comprehensions.html">
            
                <a href="comprehensions.html">
            
                    
                    推导
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="strings.html">
            
                <a href="strings.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="date-time.html">
            
                <a href="date-time.html">
            
                    
                    日期和时间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="mix-tasks.html">
            
                <a href="mix-tasks.html">
            
                    
                    自定义Mix任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="iex-helpers.html">
            
                <a href="iex-helpers.html">
            
                    
                    IEx辅助函数
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第二部分：高级</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../advanced/erlang.html">
            
                <a href="../advanced/erlang.html">
            
                    
                    和Erlang互操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../advanced/error-handling.html">
            
                <a href="../advanced/error-handling.html">
            
                    
                    错误处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../advanced/escripts.html">
            
                <a href="../advanced/escripts.html">
            
                    
                    可执行文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../advanced/concurrency.html">
            
                <a href="../advanced/concurrency.html">
            
                    
                    并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="../advanced/otp-concurrency.html">
            
                <a href="../advanced/otp-concurrency.html">
            
                    
                    OTP并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="../advanced/otp-supervisors.html">
            
                <a href="../advanced/otp-supervisors.html">
            
                    
                    OTP Supervisors
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="../advanced/otp-distribution.html">
            
                <a href="../advanced/otp-distribution.html">
            
                    
                    OTP 分布式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="../advanced/metaprogramming.html">
            
                <a href="../advanced/metaprogramming.html">
            
                    
                    元编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="../advanced/umbrella-projects.html">
            
                <a href="../advanced/umbrella-projects.html">
            
                    
                    Umbrella Projects
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="../advanced/typespec.html">
            
                <a href="../advanced/typespec.html">
            
                    
                    Specifications and types
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="../advanced/behaviours.html">
            
                <a href="../advanced/behaviours.html">
            
                    
                    行为
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="../advanced/gen-stage.html">
            
                <a href="../advanced/gen-stage.html">
            
                    
                    GenStage
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.13" data-path="../advanced/protocols.html">
            
                <a href="../advanced/protocols.html">
            
                    
                    协议
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.14" data-path="../advanced/nerves.html">
            
                <a href="../advanced/nerves.html">
            
                    
                    Nerves
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第三部分：ECTO</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../ecto/basics.html">
            
                <a href="../ecto/basics.html">
            
                    
                    Basics
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../ecto/changesets.html">
            
                <a href="../ecto/changesets.html">
            
                    
                    Changesets
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../ecto/associations.html">
            
                <a href="../ecto/associations.html">
            
                    
                    关联关系
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../ecto/querying.html">
            
                <a href="../ecto/querying.html">
            
                    
                    查询
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第四部分：专题</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../specifics/plug.html">
            
                <a href="../specifics/plug.html">
            
                    
                    Plug
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="../specifics/eex.html">
            
                <a href="../specifics/eex.html">
            
                    
                    嵌入的 Elixir(EEx)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="../specifics/ets.html">
            
                <a href="../specifics/ets.html">
            
                    
                    Erlang 项式存储(ETS)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="../specifics/mnesia.html">
            
                <a href="../specifics/mnesia.html">
            
                    
                    Mnesia 数据库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="../specifics/debugging.html">
            
                <a href="../specifics/debugging.html">
            
                    
                    调试
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">第五部分：程序库</li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../libraries/guardian.html">
            
                <a href="../libraries/guardian.html">
            
                    
                    Guardian(基础)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="../libraries/poolboy.html">
            
                <a href="../libraries/poolboy.html">
            
                    
                    Poolboy
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="../libraries/benchee.html">
            
                <a href="../libraries/benchee.html">
            
                    
                    Benchee
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="../libraries/bypass.html">
            
                <a href="../libraries/bypass.html">
            
                    
                    Bypass
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="../libraries/distillery.html">
            
                <a href="../libraries/distillery.html">
            
                    
                    Distillery(基础)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="../libraries/stream-data.html">
            
                <a href="../libraries/stream-data.html">
            
                    
                    StreamData
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >模块(Module)</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p>&#x6839;&#x636E;&#x4EE5;&#x5F80;&#x7684;&#x7ECF;&#x9A8C;&#xFF0C;&#x6211;&#x4EEC;&#x77E5;&#x9053;&#x628A;&#x6240;&#x6709;&#x7684;&#x51FD;&#x6570;&#x90FD;&#x653E;&#x5230;&#x540C;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x662F;&#x4E0D;&#x53EF;&#x63A7;&#x7684;&#x3002;&#x8FD9;&#x8282;&#x8BFE;&#x6211;&#x4EEC;&#x5C31;&#x8BB2;&#x4E00;&#x4E0B;&#x5982;&#x4F55;&#x7ED9;&#x51FD;&#x6570;&#x5206;&#x7EC4;&#xFF0C;&#x4EE5;&#x53CA;&#x5982;&#x4F55;&#x5B9A;&#x4E49;&#x4E00;&#x79CD;&#x53EB;&#x7ED3;&#x6784;&#x4F53;&#x7684;&#x7279;&#x6B8A;&#x6620;&#x5C04;&#x6765;&#x6709;&#x6548;&#x5730;&#x7EC4;&#x7EC7;&#x4EE3;&#x7801;&#x3002;</p>
<h2 id="&#x6A21;&#x5757;">&#x6A21;&#x5757;</h2>
<p>&#x6A21;&#x5757;&#x53EF;&#x4EE5;&#x8BA9;&#x6211;&#x4EEC;&#x628A;&#x628A;&#x51FD;&#x6570;&#x7EC4;&#x7EC7;&#x5230;&#x4E0D;&#x540C;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x3002;&#x9664;&#x4E86;&#x80FD;&#x4E3A;&#x51FD;&#x6570;&#x5206;&#x7EC4;&#xFF0C;&#x5B83;&#x8FD8;&#x5141;&#x8BB8;&#x6211;&#x4EEC;&#x5B9A;&#x4E49;&#x547D;&#x540D;&#x51FD;&#x6570;&#x548C;&#x79C1;&#x6709;&#x51FD;&#x6570;&#xFF0C;&#x8FD9;&#x4E2A;&#x5DF2;&#x7ECF;&#x5728;<a href="../functions">&#x524D;&#x9762;</a>&#x8BB2;&#x8FC7;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x6765;&#x770B;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x4F8B;&#x5B50;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Example</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">greeting</span></span>(name) <span class="hljs-keyword">do</span>
    <span class="hljs-string">&quot;Hello <span class="hljs-subst">#{name}</span>.&quot;</span>
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>

iex&gt; Example.greeting <span class="hljs-string">&quot;Sean&quot;</span>
<span class="hljs-string">&quot;Hello Sean.&quot;</span>
</code></pre>
<p>Elixir &#x4E5F;&#x5141;&#x8BB8;&#x5D4C;&#x5957;&#x7684;&#x6A21;&#x5757;&#xFF0C;&#x8FD9;&#x8BA9;&#x4F60;&#x53EF;&#x4EE5;&#x8F7B;&#x677E;&#x5B9A;&#x4E49;&#x591A;&#x5C42;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Example</span></span>.Greetings <span class="hljs-keyword">do</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">morning</span></span>(name) <span class="hljs-keyword">do</span>
    <span class="hljs-string">&quot;Good morning <span class="hljs-subst">#{name}</span>.&quot;</span>
  <span class="hljs-keyword">end</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">evening</span></span>(name) <span class="hljs-keyword">do</span>
    <span class="hljs-string">&quot;Good night <span class="hljs-subst">#{name}</span>.&quot;</span>
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>

iex&gt; Example.Greetings.morning <span class="hljs-string">&quot;Sean&quot;</span>
<span class="hljs-string">&quot;Good morning Sean.&quot;</span>
</code></pre>
<h3 id="&#x6A21;&#x5757;&#x5C5E;&#x6027;">&#x6A21;&#x5757;&#x5C5E;&#x6027;</h3>
<p>&#x6A21;&#x5757;&#x7684;&#x5C5E;&#x6027;&#x901A;&#x5E38;&#x88AB;&#x7528;&#x4F5C;&#x5E38;&#x91CF;&#xFF0C;&#x6765;&#x770B;&#x4E00;&#x4E0B;&#x7B80;&#x5355;&#x7684;&#x4F8B;&#x5B50;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Example</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-variable">@greeting</span> <span class="hljs-string">&quot;Hello&quot;</span>

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">greeting</span></span>(name) <span class="hljs-keyword">do</span>
    ~s(<span class="hljs-comment">#{@greeting} #{name}.)</span>
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x9700;&#x8981;&#x6CE8;&#x610F;&#x6709;&#x4E9B;&#x5C5E;&#x6027;&#x662F;&#x4FDD;&#x7559;&#x7684;&#xFF0C;&#x6700;&#x5E38;&#x7528;&#x5230;&#x7684;&#x4E09;&#x4E2A;&#x4E3A;&#xFF1A;</p>
<ul>
<li><code>moduledoc</code> &#x2014; &#x5F53;&#x524D;&#x6A21;&#x5757;&#x7684;&#x6587;&#x6863;</li>
<li><code>doc</code> &#x2014; &#x51FD;&#x6570;&#x548C;&#x5B8F;&#x7684;&#x6587;&#x6863;</li>
<li><code>behaviour</code> &#x2014; &#x4F7F;&#x7528; OTP &#x6216;&#x8005;&#x7528;&#x6237;&#x5B9A;&#x4E49;&#x7684;&#x884C;&#x4E3A;</li>
</ul>
<h2 id="&#x7ED3;&#x6784;&#x4F53;">&#x7ED3;&#x6784;&#x4F53;</h2>
<p>&#x7ED3;&#x6784;&#x4F53;&#x662F;&#x5B57;&#x5178;&#x7684;&#x7279;&#x6B8A;&#x5F62;&#x5F0F;&#xFF0C;&#x5B83;&#x4EEC;&#x7684;&#x952E;&#x662F;&#x9884;&#x5B9A;&#x4E49;&#x7684;&#xFF0C;&#x4E00;&#x822C;&#x90FD;&#x6709;&#x9ED8;&#x8BA4;&#x503C;&#x3002;&#x7ED3;&#x6784;&#x4F53;&#x5FC5;&#x987B;&#x5B9A;&#x4E49;&#x5728;&#x67D0;&#x4E2A;&#x6A21;&#x5757;&#x5185;&#x90E8;&#xFF0C;&#x56E0;&#x6B64;&#x4E5F;&#x5FC5;&#x987B;&#x901A;&#x8FC7;&#x6A21;&#x5757;&#x7684;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x6765;&#x8BBF;&#x95EE;&#x3002;
&#x7ECF;&#x5E38;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x5C31;&#x4E3A;&#x4E86;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x7ED3;&#x6784;&#x4F53;&#xFF0C;&#x5176;&#x4ED6;&#x4EC0;&#x4E48;&#x4E5F;&#x6CA1;&#x6709;&#x3002;</p>
<p>&#x8981;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x7ED3;&#x6784;&#x4F53;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528; <code>defstruct</code> &#x5173;&#x952E;&#x5B57;&#xFF0C;&#x540E;&#x9762;&#x8DDF;&#x7740;&#x5173;&#x952E;&#x5B57;&#x5217;&#x8868;&#x548C;&#x9ED8;&#x8BA4;&#x503C;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Example</span></span>.User <span class="hljs-keyword">do</span>
  defstruct <span class="hljs-symbol">name:</span> <span class="hljs-string">&quot;Sean&quot;</span>, <span class="hljs-symbol">roles:</span> []
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x6765;&#x521B;&#x5EFA;&#x4E00;&#x4E9B;&#x7ED3;&#x6784;&#x4F53;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; %Example.User{}
%Example.User&lt;<span class="hljs-symbol">name:</span> <span class="hljs-string">&quot;Sean&quot;</span>, <span class="hljs-symbol">roles:</span> [], ...&gt;

iex&gt; %Example.User{<span class="hljs-symbol">name:</span> <span class="hljs-string">&quot;Steve&quot;</span>}
%Example.User&lt;<span class="hljs-symbol">name:</span> <span class="hljs-string">&quot;Steve&quot;</span>, <span class="hljs-symbol">roles:</span> [], ...&gt;

iex&gt; %Example.User{<span class="hljs-symbol">name:</span> <span class="hljs-string">&quot;Steve&quot;</span>, <span class="hljs-symbol">roles:</span> [<span class="hljs-symbol">:manager</span>]}
%Example.User&lt;<span class="hljs-symbol">name:</span> <span class="hljs-string">&quot;Steve&quot;</span>, <span class="hljs-symbol">roles:</span> [<span class="hljs-symbol">:manager</span>]&gt;
</code></pre>
<p>&#x6211;&#x4EEC;&#x4E5F;&#x53EF;&#x4EE5;&#x50CF;&#x66F4;&#x65B0;&#x6620;&#x5C04;&#xFF08;map&#xFF09;&#x90A3;&#x6837;&#x66F4;&#x65B0;&#x7ED3;&#x6784;&#x4F53;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; steve = %Example.User{<span class="hljs-symbol">name:</span> <span class="hljs-string">&quot;Steve&quot;</span>}
%Example.User&lt;<span class="hljs-symbol">name:</span> <span class="hljs-string">&quot;Steve&quot;</span>, <span class="hljs-symbol">roles:</span> [...], ...&gt;
iex&gt; sean = %{steve | <span class="hljs-symbol">name:</span> <span class="hljs-string">&quot;Sean&quot;</span>}
%Example.User&lt;<span class="hljs-symbol">name:</span> <span class="hljs-string">&quot;Sean&quot;</span>, <span class="hljs-symbol">roles:</span> [...], ...&gt;
</code></pre>
<p>&#x66F4;&#x91CD;&#x8981;&#x7684;&#x662F;&#xFF1A;&#x7ED3;&#x6784;&#x4F53;&#x53EF;&#x4EE5;&#x5339;&#x914D;&#x6620;&#x5C04;&#xFF08;maps&#xFF09;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; %{<span class="hljs-symbol">name:</span> <span class="hljs-string">&quot;Sean&quot;</span>} = sean
%Example.User&lt;<span class="hljs-symbol">name:</span> <span class="hljs-string">&quot;Sean&quot;</span>, <span class="hljs-symbol">roles:</span> [...], ...&gt;
</code></pre>
<p>&#x5230;&#x4E86; Elixir 1.8&#xFF0C;&#x7ED3;&#x6784;&#x4F53;&#x5141;&#x8BB8;&#x5305;&#x542B;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x68C0;&#x67E5;&#x65B9;&#x5F0F;&#x3002;&#x4EE5;&#x4E0B;&#x901A;&#x8FC7;&#x67E5;&#x770B; <code>sean</code> &#x7ED3;&#x6784;&#x6765;&#x7406;&#x89E3;&#x8FD9;&#x662F;&#x5982;&#x4F55;&#x5B9E;&#x73B0;&#x7684;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; inspect(sean)
<span class="hljs-string">&quot;%Example.User&lt;name: \&quot;Sean\&quot;, roles: [...], ...&gt;&quot;</span>
</code></pre>
<p>&#x5728;&#x8FD9;&#x91CC;&#x4F8B;&#x5B50;&#xFF0C;&#x7ED3;&#x6784;&#x4F53;&#x91CC;&#x9762;&#x6240;&#x6709;&#x7684;&#x5B57;&#x6BB5;&#x90FD;&#x5C55;&#x793A;&#x51FA;&#x6765;&#x5E76;&#x6CA1;&#x6709;&#x95EE;&#x9898;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x6211;&#x4EEC;&#x60F3;&#x6392;&#x9664;&#x4E00;&#x4E9B;&#x4FDD;&#x62A4;&#x5B57;&#x6BB5;&#x5462;&#xFF1F;&#x65B0;&#x7684; <code>@derive</code> &#x529F;&#x80FD;&#x5C31;&#x80FD;&#x5B9E;&#x73B0;&#x8FD9;&#x70B9;&#x4E86;&#x3002;&#x5982;&#x4E0B;&#x4FEE;&#x6539;&#x4E00;&#x4E0B;&#x6837;&#x4F8B;&#x4E2D;&#x7684; <code>roles</code> &#x5B57;&#x6BB5;&#xFF0C;&#x5B83;&#x5C31;&#x4E0D;&#x4F1A;&#x5305;&#x542B;&#x5728;&#x8F93;&#x51FA;&#x91CC;&#x9762;&#x4E86;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Example</span></span>.User <span class="hljs-keyword">do</span>
  <span class="hljs-variable">@derive</span> {Inspect, <span class="hljs-symbol">only:</span> [<span class="hljs-symbol">:name</span>]}
  defstruct <span class="hljs-symbol">name:</span> <span class="hljs-keyword">nil</span>, <span class="hljs-symbol">roles:</span> []
<span class="hljs-keyword">end</span>
</code></pre>
<p><em>&#x5907;&#x6CE8;</em>&#xFF1A;&#x6211;&#x4EEC;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>@derive {Inspect, except: [:roles]}</code>&#xFF0C;&#x6548;&#x679C;&#x662F;&#x4E00;&#x6837;&#x7684;&#x3002;</p>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x770B;&#x770B;&#x66F4;&#x65B0;&#x540E;&#x7684;&#x6A21;&#x5757;&#x5728; <code>iex</code> &#x4E2D;&#x7684;&#x8868;&#x73B0;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; sean = %Example.User{<span class="hljs-symbol">name:</span> <span class="hljs-string">&quot;Sean&quot;</span>}
%Example.User&lt;<span class="hljs-symbol">name:</span> <span class="hljs-string">&quot;Sean&quot;</span>, ...&gt;
iex&gt; inspect(sean)
<span class="hljs-string">&quot;%Example.User&lt;name: \&quot;Sean\&quot;, ...&gt;&quot;</span>
</code></pre>
<p><code>roles</code> &#x5B57;&#x6BB5;&#x6392;&#x9664;&#x5728;&#x5916;&#x4E86;&#xFF01;</p>
<h2 id="&#x7EC4;&#x5408;&#xFF08;composition&#xFF09;">&#x7EC4;&#x5408;&#xFF08;Composition&#xFF09;</h2>
<p>&#x6211;&#x4EEC;&#x77E5;&#x9053;&#x4E86;&#x5982;&#x4F55;&#x521B;&#x5EFA;&#x6A21;&#x5757;&#x548C;&#x7ED3;&#x6784;&#x4F53;&#x4E4B;&#x540E;&#xFF0C;&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x6765;&#x5B66;&#x4E60;&#x5982;&#x4F55;&#x901A;&#x8FC7;&#x7EC4;&#x5408;&#x7684;&#x65B9;&#x5F0F;&#x4E3A;&#x6A21;&#x5757;&#x4E2D;&#x6DFB;&#x52A0;&#x65B0;&#x7684;&#x529F;&#x80FD;&#x3002;
Elixir &#x63D0;&#x4F9B;&#x4E86;&#x597D;&#x51E0;&#x79CD;&#x8BA9;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728;&#x6A21;&#x5757;&#x4E2D;&#x8BBF;&#x95EE;&#x5230;&#x5176;&#x4ED6;&#x6A21;&#x5757;&#x7684;&#x65B9;&#x5F0F;&#x3002;</p>
<h3 id="alias"><code>alias</code></h3>
<p>&#x5728; Elixir &#x4E2D;&#x975E;&#x5E38;&#x5E38;&#x89C1;&#xFF0C;&#x53EF;&#x4EE5;&#x8BA9;&#x6211;&#x4EEC;&#x901A;&#x8FC7;&#x522B;&#x540D;&#x53BB;&#x8BBF;&#x95EE;&#x6A21;&#x5757;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Sayings</span></span>.Greetings <span class="hljs-keyword">do</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">basic</span></span>(name), <span class="hljs-symbol">do:</span> <span class="hljs-string">&quot;Hi, <span class="hljs-subst">#{name}</span>&quot;</span>
<span class="hljs-keyword">end</span>

<span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Example</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-keyword">alias</span> Sayings.Greetings

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">greeting</span></span>(name), <span class="hljs-symbol">do:</span> Greetings.basic(name)
<span class="hljs-keyword">end</span>

<span class="hljs-comment"># Without alias</span>

<span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Example</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">greeting</span></span>(name), <span class="hljs-symbol">do:</span> Sayings.Greetings.basic(name)
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x5982;&#x679C;&#x522B;&#x540D;&#x6709;&#x51B2;&#x7A81;&#xFF0C;&#x6216;&#x8005;&#x6211;&#x4EEC;&#x60F3;&#x8981;&#x7ED9;&#x90A3;&#x4E2A;&#x6A21;&#x5757;&#x547D;&#x4E00;&#x4E2A;&#x4E0D;&#x540C;&#x7684;&#x540D;&#x5B57;&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x7528; <code>:as</code> &#x53C2;&#x6570;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Example</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-keyword">alias</span> Sayings.Greetings, <span class="hljs-symbol">as:</span> Hi

  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">print_message</span></span>(name), <span class="hljs-symbol">do:</span> Hi.basic(name)
<span class="hljs-keyword">end</span>
</code></pre>
<p>Elixir &#x4E5F;&#x5141;&#x8BB8;&#x4E00;&#x6B21;&#x6307;&#x5B9A;&#x591A;&#x4E2A;&#x522B;&#x540D;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Example</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-keyword">alias</span> Sayings.{Greetings, Farewells}
<span class="hljs-keyword">end</span>
</code></pre>
<h3 id="import"><code>import</code></h3>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x7528; <code>import</code> &#x4ECE;&#x53E6;&#x4E00;&#x4E2A;&#x6A21;&#x5757;&#x4E2D;&#x5BFC;&#x5165;&#x51FD;&#x6570;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; last([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>])
** (CompileError) <span class="hljs-symbol">iex:</span><span class="hljs-number">9</span><span class="hljs-symbol">:</span> undefined function last/<span class="hljs-number">1</span>
iex&gt; import List
<span class="hljs-keyword">nil</span>
iex&gt; last([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>])
<span class="hljs-number">3</span>
</code></pre>
<h4 id="&#x8FC7;&#x6EE4;">&#x8FC7;&#x6EE4;</h4>
<p>&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;<code>import</code> &#x4F1A;&#x5BFC;&#x5165;&#x6A21;&#x5757;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x51FD;&#x6570;&#x548C;&#x5B8F;&#xFF08;Macro&#xFF09;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>:only</code> &#x548C; <code>:except</code> &#x6765;&#x8FC7;&#x6EE4;&#x5BFC;&#x5165;&#x5F53;&#x524D;&#x6A21;&#x5757;&#x7684;&#x51FD;&#x6570;&#x548C;&#x5B8F;&#xFF1A;</p>
<p>&#x8981;&#x5BFC;&#x5165;&#x6307;&#x5B9A;&#x7684;&#x51FD;&#x6570;&#x548C;&#x5B8F;&#x662F;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x63D0;&#x4F9B;&#x51FD;&#x6570;&#x540D;+&#x51FD;&#x6570;&#x7684;&#x5143;&#x6570;&#x7ED9; <code>:only</code> &#x548C; <code>:except</code>&#x3002;&#x8BA9;&#x6211;&#x4EEC;&#x53EA;&#x5BFC;&#x5165;<code>last/1</code> &#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; import List, <span class="hljs-symbol">only:</span> [<span class="hljs-symbol">last:</span> <span class="hljs-number">1</span>]
iex&gt; first([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>])
** (CompileError) <span class="hljs-symbol">iex:</span><span class="hljs-number">13</span><span class="hljs-symbol">:</span> undefined function first/<span class="hljs-number">1</span>
iex&gt; last([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>])
<span class="hljs-number">3</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x518D;&#x8BD5;&#x4E0B;&#x5BFC;&#x5165;&#x9664;<code>last/1</code>&#x4E4B;&#x5916;&#x7684;&#x5176;&#x4ED6;&#x6240;&#x6709;&#x51FD;&#x6570;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; import List, <span class="hljs-symbol">except:</span> [<span class="hljs-symbol">last:</span> <span class="hljs-number">1</span>]
<span class="hljs-keyword">nil</span>
iex&gt; first([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>])
<span class="hljs-number">1</span>
iex&gt; last([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>])
** (CompileError) <span class="hljs-symbol">iex:</span><span class="hljs-number">3</span><span class="hljs-symbol">:</span> undefined function last/<span class="hljs-number">1</span>
</code></pre>
<p>&#x9664;&#x4E86;&#x6307;&#x5B9A;&#x51FD;&#x6570;&#x540D;&#x4E4B;&#x5916;&#xFF0C;Elixir &#x8FD8;&#x63D0;&#x4F9B;&#x4E86;&#x4E24;&#x4E2A;&#x7279;&#x6B8A;&#x7684;&#x539F;&#x5B50;&#xFF0C;<code>:functions</code> &#x548C; <code>:macros</code>&#xFF0C;&#x6765;&#x8BA9;&#x6211;&#x4EEC;&#x53EA;&#x5BFC;&#x5165;&#x51FD;&#x6570;&#x6216;&#x5B8F;&#xFF1A;</p>
<pre><code class="lang-elixir">import List, <span class="hljs-symbol">only:</span> <span class="hljs-symbol">:functions</span>
import List, <span class="hljs-symbol">only:</span> <span class="hljs-symbol">:macros</span>
</code></pre>
<h3 id="require"><code>require</code></h3>
<p><code>require</code> &#x7528;&#x6765;&#x544A;&#x8BC9; Elixir &#x6211;&#x4EEC;&#x8981;&#x8C03;&#x7528;&#x5176;&#x4ED6;&#x6A21;&#x5757;&#x4E2D;&#x7684;&#x5B8F;&#x3002;&#x8DDF; <code>import</code> &#x7684;&#x533A;&#x522B;&#x662F;&#xFF0C;<code>require</code> &#x5BF9;&#x5B8F;&#x6709;&#x6548;&#xFF0C;&#x800C;&#x5BF9;&#x51FD;&#x6570;&#x65E0;&#x6548;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Example</span></span> <span class="hljs-keyword">do</span>
  require SuperMacros

  SuperMacros.do_stuff
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x5982;&#x679C;&#x6211;&#x4EEC;&#x8C03;&#x7528;&#x4E86;&#x672A;&#x88AB;&#x52A0;&#x8F7D;&#x7684;&#x5B8F;&#xFF0C;Elixir &#x4F1A;&#x62A5;&#x9519;&#x3002;</p>
<h3 id="use"><code>use</code></h3>
<p><code>use</code> &#x7528;&#x6765;&#x4FEE;&#x6539;&#x6211;&#x4EEC;&#x5F53;&#x524D;&#x7684;&#x6A21;&#x5757;&#x3002;&#x5F53;&#x6211;&#x4EEC;&#x5728;&#x5F53;&#x524D;&#x6A21;&#x5757;&#x4E2D;&#x8C03;&#x7528; <code>use</code> &#x65F6;&#xFF0C;Elixir &#x4F1A;&#x6267;&#x884C;&#x6307;&#x5B9A;&#x6A21;&#x5757;&#x4E2D;&#x6240;&#x5B9A;&#x4E49;&#x7684; <code>__using__</code> &#x56DE;&#x8C03;&#x3002;</p>
<p><code>__using__</code> &#x56DE;&#x8C03;&#x6267;&#x884C;&#x7684;&#x7ED3;&#x679C;&#x4F1A;&#x6210;&#x4E3A;&#x5F53;&#x524D;&#x6A21;&#x5757;&#x5B9A;&#x4E49;&#x7684;&#x4E00;&#x90E8;&#x5206;&#x3002;&#x6211;&#x4EEC;&#x6765;&#x770B;&#x4E0B;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x4EE5;&#x4FBF;&#x66F4;&#x597D;&#x5730;&#x7406;&#x89E3; <code>use</code> &#x7684;&#x7528;&#x6CD5;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Hello</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-function"><span class="hljs-keyword">defmacro</span> <span class="hljs-title">__using__</span></span>(_opts) <span class="hljs-keyword">do</span>
    <span class="hljs-keyword">quote</span> <span class="hljs-keyword">do</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">hello</span></span>(name), <span class="hljs-symbol">do:</span> <span class="hljs-string">&quot;Hi, <span class="hljs-subst">#{name}</span>&quot;</span>
    <span class="hljs-keyword">end</span>
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x8FD9;&#x91CC;&#x6211;&#x4EEC;&#x5728; <code>Hello</code>&#x6A21;&#x5757;&#x4E2D;&#x5B9A;&#x4E49;&#x4E86; <code>__using__</code> &#x56DE;&#x8C03;&#xFF0C;&#x56DE;&#x8C03;&#x4E2D;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x540D;&#x4E3A;<code>hello/1</code>&#x7684;&#x51FD;&#x6570;&#x3002;
&#x63A5;&#x7740;&#xFF0C;&#x6211;&#x4EEC;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x6A21;&#x5757;&#x6765;&#x4F7F;&#x7528;&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Example</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-keyword">use</span> Hello
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x5728; IEx &#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x5230; <code>hello/1</code> &#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x662F;&#x5B58;&#x5728;&#x6211;&#x4EEC;&#x7684; <code>Example</code> &#x6A21;&#x5757;&#x4E2D;&#x7684;&#xFF1A;</p>
<pre><code class="lang-elixir">iex&gt; Example.hello(<span class="hljs-string">&quot;Sean&quot;</span>)
<span class="hljs-string">&quot;Hi, Sean&quot;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x5C55;&#x793A;&#x4E86; <code>__using__/1</code> &#x56DE;&#x8C03;&#x7684;&#x57FA;&#x672C;&#x7528;&#x6CD5;&#xFF0C;&#x5C06; <code>Hello</code> &#x6A21;&#x5757;&#x4E2D;&#x7684;<code>__using__/1</code>&#x56DE;&#x8C03;&#x7684;&#x6267;&#x884C;&#x7ED3;&#x679C;&#x6DFB;&#x52A0;&#x5230;&#x4E86; <code>Example</code> &#x6A21;&#x5757;&#x4E2D;&#xFF0C;&#x6210;&#x4E86;<code>Example</code>&#x6A21;&#x5757;&#x5B9A;&#x4E49;&#x7684;&#x4E00;&#x90E8;&#x5206;&#x3002;</p>
<p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x6765;&#x5B66;&#x4E60;&#x5982;&#x4F55;&#x5E94;&#x7528;<code>__using__/1</code>&#x56DE;&#x8C03;&#x4E2D;&#x7684;&#x53C2;&#x6570;&#x3002; &#x8BA9;&#x6211;&#x4EEC;&#x6765;&#x4E3A;&#x4E0A;&#x9762;&#x4F8B;&#x5B50;&#x4E2D;&#x7684;<code>__using_</code>&#x56DE;&#x8C03;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A; <code>greeting</code> &#x53C2;&#x6570;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Hello</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-function"><span class="hljs-keyword">defmacro</span> <span class="hljs-title">__using__</span></span>(opts) <span class="hljs-keyword">do</span>
    greeting = Keyword.get(opts, <span class="hljs-symbol">:greeting</span>, <span class="hljs-string">&quot;Hi&quot;</span>)

    <span class="hljs-keyword">quote</span> <span class="hljs-keyword">do</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">hello</span></span>(name), <span class="hljs-symbol">do:</span> unquote(greeting) &lt;&gt; <span class="hljs-string">&quot;, &quot;</span> &lt;&gt; name
    <span class="hljs-keyword">end</span>
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x7136;&#x540E;&#x6211;&#x4EEC;&#x5728; <code>Example</code> &#x6A21;&#x5757;&#x4E2D;&#x4F7F;&#x7528;&#x65B0;&#x52A0;&#x7684;&#x8FD9;&#x4E2A; <code>greeting</code> &#x53C2;&#x6570;&#xFF1A;</p>
<pre><code class="lang-elixir"><span class="hljs-class"><span class="hljs-keyword">defmodule</span> <span class="hljs-title">Example</span></span> <span class="hljs-keyword">do</span>
  <span class="hljs-keyword">use</span> Hello, <span class="hljs-symbol">greeting:</span> <span class="hljs-string">&quot;Hola&quot;</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>&#x6211;&#x4EEC;&#x6253;&#x5F00; IEx &#x6765;&#x9A8C;&#x8BC1; <code>greeting</code> &#x7684;&#x5185;&#x5BB9;&#x5DF2;&#x7ECF;&#x88AB;&#x6539;&#x53D8;&#x4E86;&#xFF1A;</p>
<pre><code>iex&gt; Example.hello(&quot;Sean&quot;)
&quot;Hola, Sean&quot;
</code></pre><p>&#x4E0A;&#x9762;&#x8FD9;&#x4E9B;&#x7B80;&#x5355;&#x7684;&#x4F8B;&#x5B50;&#x5C55;&#x793A;&#x4E86; <code>use</code> &#x7684;&#x7528;&#x6CD5;&#x3002;<code>use</code> &#x662F; Elixir &#x5DE5;&#x5177;&#x7BB1;&#x4E2D;&#x975E;&#x5E38;&#x5F3A;&#x5927;&#x7684;&#x4E00;&#x4E2A;&#x3002;&#x5728;&#x4F60;&#x5B66;&#x4E60; Elixir &#x7684;&#x8FC7;&#x7A0B;&#x4E2D;&#xFF0C;&#x591A;&#x7559;&#x610F;&#x4E00;&#x4E0B;&#xFF0C; &#x4F60;&#x4F1A;&#x770B;&#x5230;&#x5F88;&#x591A;&#x4F7F;&#x7528; <code>use</code> &#x7684;&#x5730;&#x65B9;&#xFF0C;&#x4E4B;&#x524D;&#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x9047;&#x5230;&#x8FC7;&#x7684;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#x5C31;&#x662F; <code>use ExUnit.Case, async: true</code>&#x3002;</p>
<p><strong>&#x6CE8;&#x610F;</strong>: <code>quote</code>, <code>alias</code>, <code>use</code>, <code>require</code> &#x90FD;&#x662F;&#x5B8F;&#xFF0C;&#x6211;&#x4EEC;&#x4F1A;&#x5728;<a href="../../advanced/metaprogramming">&#x5143;&#x7F16;&#x7A0B;</a>&#x4E00;&#x8282;&#x5B66;&#x5230;&#x66F4;&#x591A;&#x6709;&#x5173;&#x5B8F;&#x7684;&#x77E5;&#x8BC6;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="pipe-operator.html" class="navigation navigation-prev " aria-label="Previous page: 管道操作符">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="mix.html" class="navigation navigation-next " aria-label="Next page: Mix">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"version":"1.4.1","title":"模块(Module)","level":"1.9","depth":1,"next":{"title":"Mix","level":"1.10","depth":1,"path":"lessons/basics/mix.md","ref":"lessons/basics/mix.md","articles":[]},"previous":{"title":"管道操作符","level":"1.8","depth":1,"path":"lessons/basics/pipe-operator.md","ref":"lessons/basics/pipe-operator.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"lessons/basics/modules.md","mtime":"2019-11-05T02:25:51.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-11-05T03:01:22.004Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

